require('../../mypublic/css/common.less');
require('../../mypublic/css/index.less');

require('../../public/misc/mediaUpload/css/style.css');
require('../../public/misc/jquery.jqGrid-4.6.0/css/ui.jqgrid.css');
require('../../public/misc/jquery-ui-themes-1.11.2/humanity/jquery-ui.min.css');


require("jquery");

require('../../public/misc/jquery.jqGrid-4.6.0/js/i18n/grid.locale-cn');
require('../../public/misc/jquery.jqGrid-4.6.0/js/jquery.jqGrid.min');

require('../../public/js/myservice/side');
require("../../public/js/myservice/authorize");

oriFunc();

function oriFunc() {
    $('#grid-table').jqGrid(
        {
            url: '/api/index.php?r=/cms/dir/index',
            treeGrid: true,
            treedatatype: 'json',
            treeGridModel: 'adjacency',
            ExpandColumn: 'id',
            ExpandColClick: true,
            colNames: [
                '#编号',
                '编码',
                '名称',
                '简要描述',
                '排序',
                '发布状态',
                '对外显示'
            ],
            colModel: [
                {index: 'id', name: 'id', align: 'left', sortable: false, width: 50},
                {index: 'code', name: 'code', align: 'center', sortable: false, width: 80},
                {index: 'name', name: 'name', align: 'center', sortable: false, editable: true, width: 80},
                {
                    index: 'short_desc',
                    name: 'short_desc',
                    align: 'left',
                    sortable: false,
                    editable: true,
                    width: 150
                },
                {index: 'sort', name: 'sort', align: 'center', sortable: false, editable: true, width: 80},
                {
                    index: 'status',
                    name: 'status',
                    width: 50,
                    align: 'center',
                    sortable: false,
                    editable: true,
                    edittype: 'checkbox',
                    formatter: 'checkbox',
                    editoptions: {value: '1:0'}
                },
                {
                    index: 'external_display',
                    name: 'external_display',
                    width: 50,
                    align: 'center',
                    sortable: false,
                    editable: true,
                    edittype: 'checkbox',
                    formatter: 'checkbox',
                    editoptions: {value: '1:0'}
                }
            ],
            datatype: 'json',
            height: 'auto',
            autowidth: true,
            viewrecords: false,
            pager: $('#grid-pager'),
            cellEdit: true,
            cellurl: '/api/index.php?r=/cms/dir/quick-set',
            afterSubmitCell: function (serverresponse, rowid, cellname, value, iRow, iCol) {
                if ('' != serverresponse.responseText) {
                    var response = $.parseJSON(serverresponse.responseText);
                    return [false, response.errMsg];
                } else return [true];
            },
            loadComplete: function () {
                $('#search-btn').attr('disabled', false);
            },
            ondblClickRow: function (id) {
                window.location.href = '/cms/dir_edit/index.html?id=' + id;
            }
        }
    ).navGrid(
        '#grid-pager',
        // options
        {
            search: false,
            addfunc: function () {
                window.location.href = '/cms/dir_edit/index.html';
            },
            editfunc: function (id) {
                window.location.href = '/cms/dir_edit/index.html?id=' + id;
            }
//            del: false
        },
        // edit
        {},
        // add
        {},
        // del
        {
            url: '/api/index.php?r=/cms/dir/delete',
            reloadAfterSubmit: true,
            afterSubmit: function (data, datapost) {
                if (data.responseText) {
                    var json = eval('(' + data.responseText + ')');
                    return [json.status, json.status ? '' : json.errMsg, ''];
                } else {
                    return [true, '', ''];
                }
            }
        }
    );
}
